<?php $this->beginBlock('pageTitle')?>
<a href="/" title="FankersDoc" class="book-title">
    FankersDoc
</a>
<?php $this->endBlock()?>
<div class="row" style="margin: 90px 0 0 0">
    <div class="col-sm-offset-4 col-sm-4">
        <div class="panel panel-default">
            <div class="panel-heading text-center">用户登录</div>
            <div class="panel-body">
                <form onsubmit="return false" id="userInfo">
                    <input type="hidden" name="<?=Yii::$app->request->csrfParam?>" value="<?=Yii::$app->request->csrfToken?>">
                    <div class="input-group">
                        <span class="input-group-addon"><i class="fa fa-user-o"></i></span>
                        <input type="text" class="form-control" name="username" placeholder="用户名">
                    </div>
                    <div class="input-group m-t-20">
                        <span class="input-group-addon"><i class="fa fa-key"></i></span>
                        <input type="text" class="form-control" name="password_hash" placeholder="密码">
                    </div>
                    <div class="input-group m-t-20">
                        <span class="input-group-addon"><i class="fa fa-check-square"></i></span>
                        <input type="text" class="form-control" name="code" placeholder="验证码">
                        <span class="input-group-addon"><img src="<?=\yii\helpers\Url::toRoute('auth/captcha')?>"></span>

                    </div>
                    <div class="form-group m-t-20">
                        <button type="button" class="btn btn-primary btn-sm btn-block" onclick="loginObj.doLogin()">登 录</button>
                    </div>

                    <div class="form-group m-t-20">
                        还没有账号？<a href="<?=\yii\helpers\Url::toRoute(['auth/register'])?>" title="立即注册">立即注册</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<?php $this->beginBlock('jsFooterText')?>
<script>
    var loginObj = {
        loginLock : false,
        // 登录
        doLogin:function () {
            var data = $('#userInfo').serialize();
            var url = '<?=\yii\helpers\Url::toRoute('auth/login')?>';
            that = this;

            if (that.loginLock)return false;
            that.loginLock = true;

            $.ajax({
                type:'post',
                url:url,
                data:data,
                dataType:'json',
                success:function(resp){
                    that.loginLock = false;
                    if (resp.e === '0'){
                        layer.msg(resp.m, {icon: 6});
                        window.location.href = resp.d;
                    } else {
                        layer.msg(resp.m, {icon: 5});
                    }
                },
                error:function(err){
                    that.loginLock = false;
                    layer.msg('服务器正忙,请稍后重试', {icon: 5});
                }
            });
        }
    };
</script>
<?php $this->endBlock()?>
